﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TokenAuthority
{
    public class Token : IComparable<Token>
    {

        public string UID { get; private set; }
        private Dictionary<string, string> _metadata = new Dictionary<string, string>();
        public Dictionary<string, string> Metadata
        {
            get
            {
                var dict = new Dictionary<string, string>();
                foreach (var entry in _metadata)
                    dict.Add((string)entry.Key.Clone(), entry.Value.Clone() as string);
                return dict;
            }
        }

        public Token(string username, string ip)
        {
            UID = Guid.NewGuid().ToString();
        }

        public Token()
            : this(string.Empty, string.Empty)
        {
            UID = Guid.NewGuid().ToString();
        }

        public bool Add(string key, string value)
        {
            if (!_metadata.ContainsKey(key))
            {
                _metadata.Add(key, value);
                return true;
            }
            return false;
        }


        public int CompareTo(Token other)
        {
            return other.UID.CompareTo(UID);
        }
    }
}
